﻿using UnityEngine;

namespace Core
{
    public abstract class AbstractNode : Component//, IDataElement //IAwake
    {
        public Vector2Int Coord { get; set; }

        public GameObject gameObject { get; private set; }
        public Transform transform { get; private set; }
        public Vector3 initialPosition { get; private set; }
        public bool Active { get; private set; }

        public virtual void Awake(GameObject go, Vector3 pos)
        {
            gameObject = go;
            transform = go.transform;
            initialPosition = pos;
        }

        public override void Dispose()
        {
            if (IsDisposed) return;
            base.Dispose();

            gameObject = null;
            transform = null;
        }

        public virtual void SetActive(bool active)
        {
            Active = active;
            Utils.Trans.SetActive(gameObject, active);
            if (active)
            {
                OnShow();
            }
            else
            {
                OnHide();
            }
        }

        protected virtual void OnShow()
        {

        }

        protected virtual void OnHide()
        {

        }
    }
}
